﻿using cefsharpwpf.log;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace cefsharpwpf
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {

        private static System.Timers.Timer loopTimer;
        public MainWindow()
        {
            InitializeComponent();
            loopTimer = new System.Timers.Timer();
            loopTimer.Interval = 5000;
            loopTimer.Enabled = false;
            loopTimer.Elapsed += timer_Elapsed;
            loopTimer.AutoReset = true;
        }

        private void btn_changeLabel1_Click(object sender, RoutedEventArgs e)
        {

            string passwordtext = pwdkeyboard.PassWordInput;
            lb1.Content = passwordtext;                 


        }

        private void btn_Close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Grid_TouchDown(object sender, TouchEventArgs e)
        {
       
                      
        }

        private void Grid_KeyDown(object sender, KeyEventArgs e)
        {
            
            LogManager.WriteLog(e.ToString());
        }

       

        private void Grid_MouseMove(object sender, MouseEventArgs e)
        {
            LogManager.WriteLog("鼠标移动事件"+e.ToString());
        }

       
      

        private void Grid_MouseLeave(object sender, MouseEventArgs e)
        {
            LogManager.WriteLog("鼠标leave事件" + e.ToString());

        }

        private void Grid_MouseEnter(object sender, MouseEventArgs e)
        {
            LogManager.WriteLog("鼠标enter事件" + e.ToString());
        }

        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            LogManager.WriteLog("鼠标down事件" + e.ToString());
        }

        private void Grid_MouseUp(object sender, MouseButtonEventArgs e)
        {
            LogManager.WriteLog("鼠标up事件" + e.ToString());
        }

        private void Grid_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            LogManager.WriteLog("鼠标wheel事件" + e.ToString());
        }

        private void Window_MouseEnter(object sender, MouseEventArgs e)
        {
            LogManager.WriteLog("window鼠标down事件" + e.ToString());         
        }

       

        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            LogManager.WriteLog("window鼠标down事件" + e.ToString());
            var mpt = e.GetPosition(this);
            double PSW = SystemParameters.PrimaryScreenWidth;
            double PSH = SystemParameters.PrimaryScreenHeight;
            double AW = this.ActualWidth;
            double AH = this.ActualHeight;
            double X = mpt.X;
            double Y = mpt.Y;




            LogManager.WriteLog("屏幕的宽度:" + PSW + "屏幕的高度:" + PSH);
            LogManager.WriteLog("窗口的宽度:" + AW + "窗口的高度:" + AH);
            LogManager.WriteLog("x:" + X + "y:" + Y);

            bool IsLeftDownPosition = (X >= 0 & X <= 50) & (Y >= (AH - 50) & Y <= AH);
            LogManager.WriteLog(IsLeftDownPosition.ToString());
            if (IsLeftDownPosition)
            {
                LogManager.WriteLog("位置正确");


                loopTimer.Enabled = true;
            }                   
        }
        PassWordKeyBoard pwkb = new PassWordKeyBoard();
        void timer_Elapsed(Object sender, System.Timers.ElapsedEventArgs e)
        {
           
             MessageBox.Show("时间到！！！");
          //  grid1.Children.Add(pwkb);
            grid1.Dispatcher.Invoke(
                new Action(
                    delegate
                    {                        
                        grid1.Children.Add(pwkb);
                    }
                    )
                );
        }

        private void Window_MouseUp(object sender, MouseButtonEventArgs e)
        {
            loopTimer.Enabled = false;
        }
    }
}
